# Maintainer: taotieren <admin@taotieren.com>

pkgname=qucs-s-git
pkgver=25.2.0.r310.g78d4bc31
pkgrel=1
epoch=
pkgdesc="Qucs-S provides GUI for different circuit simulation kernels. "
arch=($CARCH)
url="https://github.com/ra3xdh/qucs_s"
license=('GPL-2.0-only')
_qt=qt6
groups=()
depends=(
    sh
    gcc-libs
    glibc
    graphicsmagick
    hicolor-icon-theme
    imagemagick
    ngspice
    python
    python-numpy
    python-matplotlib
    #     python-parse
    $_qt-base
    $_qt-charts
    $_qt-svg
    octave)
makedepends=(
    cmake
    dos2unix
    ninja
    git
    autoconf
    automake
    perl-gd
    perl-xml-libxml
    gperf
    libcups
    libtool
    mesa
    flex
    bison
    $_qt-tools
)
optdepends=(
    'ngspice: Mixed-level/Mixed-signal circuit simulator based on Spice3f5, Ciber1b1, and Xspice'
    'spiceopus: Spice Opus is a free general purpose circuit simulator specially suited for optimization loops'
    'qucsator: An integrated circuit simulator'
    'qucs: for Qucsator simulation backend'
    'freehdl: to permit digital circuit simulation'
    'asco: to enable circuit optimization'
    'openvaf: A Next-Generation Verilog-A compiler https://openvaf.semimod.de/'
    'qucs-rflayout: Export Qucs RF schematics to KiCad layouts & OpenEMS scripts')
checkdepends=()
optdepends=()
provides=(${pkgname%-git})
conflicts=(${pkgname%-git})
replaces=()
backup=()
options=('!makeflags')
install=
changelog=
source=("${pkgname}::git+${url}.git"
    "qucsator_rf::git+https://github.com/ra3xdh/qucsator_rf.git")
noextract=()
sha256sums=('SKIP'
    'SKIP')
validpgpkeys=()

pkgver() {
    cd "${srcdir}/${pkgname}"
    (
        set -o pipefail
        git describe --exclude 'continuous_build' --long 2>/dev/null | sed 's/^v//g;s/\([^-]*-g\)/r\1/;s/-/./g' ||
            printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short=7 HEAD)"
    )
}

prepare() {
    git -C "${srcdir}/${pkgname}" clean -dfx
    cd "${srcdir}/${pkgname}"
    git submodule init
    git config submodule.qucsator_rf.url "$srcdir/qucsator_rf"
    git -c protocol.file.allow=always submodule update
}

build() {
    cd "${srcdir}/${pkgname}"

    cmake -D CMAKE_INSTALL_PREFIX=/usr \
        -DWITH_QT6=ON \
        -B build \
        -G Ninja

    ninja -C build
}

package() {
    cd "${srcdir}/${pkgname}"
    DESTDIR="${pkgdir}" ninja -C "${srcdir}"/${pkgname}/build install
}
